package softtech.app.secretcaller;

import java.util.Calendar;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BroadcastDateTimeChange extends BroadcastReceiver {
	final String TAG = "DateTimeChangeReceive";
	final String TAG_BROADCAST = "ALARM_SMS";

	@Override
	public void onReceive(Context context, Intent intent) {		

		if (intent.getAction().compareTo(Intent.ACTION_BOOT_COMPLETED) == 0) {

			Log.e(TAG, "DemoReceiver.onReceive(ACTION_BOOT_COMPLETED)");

			context.startService(new Intent(context, ServiceDateTimeChange.class));

		} else if (intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0){
			
			Calendar cal = Calendar.getInstance();
			Log.e(TAG  , "hour = "+ cal.get(Calendar.HOUR_OF_DAY) + " minute ="+cal.get(Calendar.MINUTE));
			
			ConnectionDetector cd = new ConnectionDetector(context);
			if(!cd.isConnectingToInternet()){
				return;
			}
			
			//if( cal.get(Calendar.HOUR_OF_DAY) %12 == 0 && cal.get(Calendar.MINUTE) ==0 ){
			if( cal.get(Calendar.MINUTE) ==0 ){
				ControlsSyncSecretContact taskSyncSecret = new ControlsSyncSecretContact(context);
				taskSyncSecret.execute(null,null,null);
			}
		}
		
	}
	
	
	
}
